import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:Java方法的学习
 * User: LianBao
 * Date: 2024-02-03
 * Time: 21:48
 */
public class Test {

    //public static 返回值 方法名(参数){ 方法体 }
    //方法必须写在类里面,方法不能嵌套(不能写在main方法中,但是写在main之前和之后都行)
    public static int Add(int x,int y) {
        return x+y;
    }

    public static void swap(int a,int b) {
        //看似交换,其实没有交换,Java中没有指针,不能取地址,如果要真正的交换,就得把他们放在堆上(变量放在栈上),数组是放在堆上的
        int tmp = a;
        a = b;
        b = tmp;
    }


    //方法重载()
    //1.方法名称必须一样,参数的数据类型/个数/顺序不一样,返回值没要求
    public static int sum(int x,int y) {
        return x+y;
    }
    public static double sum(double x,double y) {
        return x+y;
    }


    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        int ret = Add(10,20);
        //函数调用的过程:函数栈帧,和C语言一样的
    }


    public static int Func(int n) {
        if(n==1) {
            return 1;
        } else if (n==0){
            return 0;
        } else {
            return Func(n-1)+Func(n-2);
        }
    }
    public static void main6(String[] args) {
        System.out.println(Func(1));
        System.out.println(Func(2));
        System.out.println(Func(3));
        System.out.println(Func(4));
        System.out.println(Func(5));
    }

    public static int max2(int x,int y) {
        if(x>y) {
            return x;
        } else {
            return y;
        }
    }
    public static int max3(int x,int y,int z) {
        if (max2(x,y)==x) {
            //x>y
            if (max2(x,z)==x) {
                //x>z
                return x;
            } else {
                //x<z
                return z;
            }
        } else {
            //y>x
            if(max2(y,z)==y) {
                return y;
            } else {
                return z;
            }
        }
    }

    public static void main4(String[] args) {
        int cmp2 = max2(10,20);
        int cmp3 = max3(10,20,30);
        System.out.println(cmp2);
        System.out.println(cmp3);
    }

    public static void main3(String[] args) {
        int num = 1234;
        while (num>0) {
            System.out.printf("%d ",num%10);
            num/=10;
        }
    }

    public static void main2(String[] args) {
        int count =0;
        Scanner scan = new Scanner(System.in);
        String password = "hello";
        while (count<3) {
            String password_scan = scan.next();
            if(password.equals(password_scan)) {
                System.out.println("密码正确!");
                break;
            } else {
                System.out.println("输入错误,请重新输入!");
            }
            count++;
        }
        if(count==3) {
            System.out.println("三次密码输入均错误,退出程序");
        }
    }

    public static void main1(String[] args) {

        double sum = 0;
        int flag =1;
        for (int i = 1; i <= 100; i++) {
            int ret = i;
            if(i%2==0){
                flag = -1;//偶数
            } else {
                flag=1;
            }
            sum+=((1.0/ret)*flag);
        }
        System.out.println(sum);
    }

}
